	
function get_content(url_read, url_write, domain_used, biov_domain, id){
	var q  = '{"query":[{"name":null,'+
						'"guid":null,'+
						'"id":"'+id+'",'+						
						'"type":"'+biov_domain+'technology_class",'+
						'"parent_technology":[{"*":null,"optional":true}],'+
						'"related_technology":[{"*":null,"optional":true}],'+
						'"includes_technology":[{"*":null,"optional":true}],'+
						'"company_involved":[{"*":null,"optional":true, "sort":"name", "area_of_expertise":[{"name":null,"id":null}]}],'+
						'"products_involving_this_technology":[{"*":null,"sort":"name", "optional":true}]'+
						'}]}';
						
	perform_freebase_read(
		url_read,
		q,
		function (msg) {
			var technology = null;
			technology = msg.result[0];
            if (!technology) return;
            
            var technologyInfo = Object(); // Formatted verstion of the technology information.

	        //name
	        var name = technology.name;
	        $('#title').text(name);
            			
            // IDs
            technologyInfo.id = technology.id;
            technologyInfo.guid = technology.guid;	
            			
			// Overview blurb and Topic Image
			var topic_domain = biov_domain+'technology_class';
			jsonp_totalblurb_freebase(domain_used, name, topic_domain, 500,
				function(m){
					$("#thumb").attr('src','http://'+domain_used+'/api/trans/image_thumb'+m.result[0].image.id);
				},
				function(m){
					$("#description").append($('<span>'+m.result.body+'</span>'));
				},
				function(m){}
			);
 			
			var techLinkInfo = Object();
			techLinkInfo.useLink = true;
			techLinkInfo.relDir = 'technology';
 			
			// Parent Technologies
	        var parentTechnologyList = technology.parent_technology;
	        if(parentTechnologyList.length>0){
	        	createListWithHeader(parentTechnologyList,'Parent technologies:','partech_div', 3, techLinkInfo, false,-1);
	        	//createTechnologyTable(parentTechnologyList,'parentTechnologiesHeader', 'partech_div', 'Parent technologies',topic_domain, domain_used);
			}
			technologyInfo.parent_technologies = parentTechnologyList;
			
			// Related Technologies
	        var relatedTechnologyList = technology.related_technology;
	        if(relatedTechnologyList.length>0){
	        	createListWithHeader(relatedTechnologyList,'Related technologies:','reltech_div', 3, techLinkInfo, false,-1);
	        	//createTechnologyTable(relatedTechnologyList,'relatedTechnologiesHeader', 'reltech_div', 'Related technologies',topic_domain, domain_used);
			}
			technologyInfo.related_technologies = relatedTechnologyList;

			// Technologies Included
	        var subTechnologyList = technology.includes_technology;
	        if(subTechnologyList.length>0){
	        	createListWithHeader(subTechnologyList,'Includes technologies:','subtech_div', 3, techLinkInfo, false,-1);
	        	//createTechnologyTable(subTechnologyList,'subTechnologiesHeader', 'subtech_div', 'Includes technologies',topic_domain, domain_used);
			}
			technologyInfo.included_technologies = subTechnologyList;
			
			// Read products for this technology and all sub-technologies (property: includes_technologies)
			var allTechnologies = '"'+name+'"';
			for(var k=0;k<subTechnologyList.length;k++){
				allTechnologies += ( k < subTechnologyList.length ? ', ' :"");
				allTechnologies += '"'+subTechnologyList[k].name+'"';
			}
			read_products(allTechnologies, url_read, domain_used, biov_domain, name);
			technologyInfo.products = technology.products_involving_this_technology;
			
			// Companies involved in the technology
			var companies = technology.company_involved;
			//create_company_table(companies, topic_domain, domain_used, biov_domain);
			createListWithHeader(companies,'Companies involved:','comp_div', 3, techLinkInfo, false,-1);
			technologyInfo.companies = companies;
			
			// Get the completion score for the disease:
			var completion_score = calculateTechnologyCompletion(technologyInfo);
			var completion_string = '<input type="submit" id="completion_button" value="'+technology.name+' is only '+completion_score+'% complete. Create an Account to Add More Content!"></input>';		
			var completion_string_login = '<div>'+technology.name+' is  '+completion_score+'% complete. </div>';		
			$("#completion_score").append(completion_string);
			$("#completion_button").bind("click", function(e){
	        	//location.href = "{% url registration.views.register %}";
				location.href = '/account/register'
			})
			$("#completion_score_login").append(completion_string_login);			
			
			
			// Add the Edit form:
			write_overview(url_read, url_write, domain_used, biov_domain, technologyInfo, name);
									
		},
		function(m){}
	);
}

function calculateTechnologyCompletion(technologyInfo){
	var score = 0;
	
	if(typeof(technologyInfo.parent_technologies) != 'undefined') {
		if(technologyInfo.parent_technologies.length>0){
			score += 15;
		}
	}
	if(typeof(technologyInfo.related_technologies) != 'undefined'){
		if(technologyInfo.related_technologies.length>0){
			score += 15;
		}
	}
	if(typeof(technologyInfo.included_technologies) != 'undefined'){
		if(technologyInfo.included_technologies.length>0){
			score += 15;
		}
	}
	if(typeof(technologyInfo.products) != 'undefined'){
		if(technologyInfo.products.length>0){
			score += 15;
		}
	}
	if(typeof(technologyInfo.companies) != 'undefined'){
		if(technologyInfo.companies.length>0){
			score += 15;
		}
	}
	return score;
}


/* 
	Creates a technology table
 */
function createTechnologyTable(vals,htmlID_h, htmlID, header_val,topic_domain, domain_used){
    var parTData = new google.visualization.DataTable();
	parTData.addColumn('string', '');
	parTData.addColumn('string', '');
   	parTData.addColumn('string', '');
 	parTData.addRows(vals.length);

	var parTable = new google.visualization.Table(document.getElementById(htmlID));
   	var parView = new google.visualization.DataView(parTData);
  	parView.setColumns([0,1]);
  	var names = Array();
    if(vals.length > 0) {
    	var h = '<h3>'+header_val+'</h3>';
    	$("#"+htmlID_h).append($(h));
				
		for (var i in vals) {
			var technologyName = vals[i].name;
			names[i] = technologyName;
			var techLink = '<a href="'+create_bvr_topic_href('technology', vals[i].id)+ '">' + technologyName + '</a>';
			parTData.setCell(parseFloat(i), 0, techLink);
			x(i,1,2,parTData, parView, technologyName, topic_domain, domain_used, parTable, 500, 150);
			parTable.draw(parView, {allowHtml: true});
		}				
	}

}

function create_company_table(companies, topic_domain, domain_used, biov_domain){
//	var q =  '{"query":[{"area_of_expertise":[{"name":"'+name+'"}],"name" : null, "type":"/base/bioventurist/science_or_technology_company","a:area_of_expertise":[]}]}';
	
    if(companies.length > 0) {
    	var topic_domain = biov_domain+'science_or_technology_company';
    	var comp = new google.visualization.DataTable();
		comp.addColumn('string', 'Company');
		comp.addColumn('string', 'Technologies Involoved In');
		comp.addColumn('string', 'Overview');
		comp.addColumn('string', '');
 		comp.addRows(companies.length);
	
		var table = new google.visualization.Table(document.getElementById('comp_div'));
       	var view = new google.visualization.DataView(comp);
  		view.setColumns([0,1,2]);
  		var expandedRow = -1;
			
		for (var i in companies) {
			var companyName = companies[i].name;
			var cName = '<a href="'+create_bvr_topic_href('company', companies[i].id)+'">' + companyName + '</a>';
				
			comp.setCell(parseFloat(i), 0, cName);
				
			var company = companies[i];
			var technologies = companies[i].area_of_expertise;
				
			var tNames = ''
			for (var j in technologies) {
				var expertise = technologies[j];
				tNames += '<a href="'+create_bvr_topic_href('technology',technologies[j].id)+'">'+technologies[j].name+'</a>'
				tNames += ( j < technologies.length-1 ? ', ' :"");
			}
			comp.setCell(parseFloat(i), 1, tNames);
				
 		 	x(i,2,3,comp,view, companyName, topic_domain, domain_used,  table, 500, 150);
	   	    	
		}
	 	var verboses = Array(technologies.length);
	 	for (var i=0;i<technologies.length;i=i+1) {	 	
	 		verboses[i] = false;
	 	}	
	 	table.draw(comp, {allowHtml: true, page: 'enable', pageSize: 20, showRowNumber: true});
	 	$("p.expander").css("color","#2A524F"); 	
		$(".expander").click(function () { 
  			 verboses = setSelectionExpander2(comp, table, view,verboses,2, 3);
		});
/* 
				google.visualization.events.addListener(table, 'select', function() {
		 				verboses = setSelectionExpander2(comp, table, view,verboses,2, 3);
				});
				*/
		table.draw(comp, {allowHtml: true, page: 'enable', pageSize: 5, showRowNumber: true});							
	}
}

function read_products(allTechnologies, url_read, domain_used, biov_domain, name){

	var q = '{"query":[{"name":null,"id":null, "technology_involved|=":['+allTechnologies+'],"type":"'+biov_domain+'product","brand_name":[],"developed_by":[{"name":null,"id":null, "optional":true}],"a:type":[],"stage_of_development":null,"sales":[{"year":null,"amount":null,"area":null, "optional":true}]}]}'; 

	perform_freebase_read(
		url_read,
		q,
		function (msg) {
			var product = null;
			product = msg.result[0];
			var products = msg.result;
	        if (!product) return;
	        
	        /*  TODO make the productObj return:
	        *
	        *	productObj.prodOnMarket;
        	*	productObj.prodInDev;
        	*	productObj.therOnMarket;
        	*	productObj.therInDev;
	    	 */
        	var productObj = getProductTypes(products, "a:type");
	        if(productObj.products.length > 0) {
	        
				var h_ProdMarket = '<h3>Products on the Market</h3>';
				h_ProdMarket = $(h_ProdMarket)
				$("#h_ProdMarket").append(h_ProdMarket); 
				var h_ProdDev = '<h3>Products in Development</h3>';
				h_ProdDev = $(h_ProdDev)
				$("#h_ProdDiv").append(h_ProdDev); 
	                	
				var marketCols = [0,2,4,5];
				var devCols = [0,2,4];
				barOptions = Object();
				barOptions.salesByCompanies = true;
				barOptions.salesByProducts = false;
	        	createProductTable(productObj.products, domain_used, biov_domain, marketCols, devCols, barOptions);
			}
			if(productObj.therapeutics.length > 0){
				
				var h_TherMarket = '<h3><span>Therapeutics on the Market</span></h3>';
				h_TherMarket = $(h_TherMarket)
				$("#h_TherMarket").append(h_TherMarket); 
				var h_TherMarket = '<h3><span>Therapeutics in Development</span></h3>';
				h_TherMarket = $(h_TherMarket)
				$("#h_TherDiv").append(h_TherMarket); 
				
				// Need to query for therapeutic properties.
				var qThera = '{"query":[{"'+biov_domain+'bv_therapeutic/biomolecule_or_target":[],"'+biov_domain+'bv_therapeutic/indication_or_disease":[{"disease":[{"name":null,"id":null}],"optional":true,"phase_of_development":null}],"a:type":[],"brand_name":[],"a:developed_by":[{"name":null,"id":null}],"name":null,"id":null,"sales":[{"amount":null,"area":null,"optional":true,"year":null}],"stage_of_development":null,"technology_involved":"'+name+'","type":"'+biov_domain+'product"}]}'; 
				//createTherapeuticTable(productObj.therapeutics, domain_used);
				perform_freebase_read(
					url_read,
					qThera,
					function (msg2) {
						var therapeutics = null;
						therapeutics = msg2.result;
						if(therapeutics.length > 0){
							var marketCols = [0,1,2,3];
							var devCols = [0,1,2];
							var barOptions = Object();
							barOptions.salesByCompanies = true;
							barOptions.salesByProducts = false;
							var companyOptions = Object();
							companyOptions.specifyCompany = false;
							companyOptions.companyName = '';
							createTherapeuticsTable(therapeutics, domain_used, biov_domain, marketCols, devCols, barOptions, false, companyOptions);		
						}
					},
					function(m){}
				);
			}
        },
  		function(m){}
	);
}